package com.turing.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.turing.system.entity.SysMenu;
import com.turing.system.service.SysMenuService;
import com.turing.system.mapper.SysMenuMapper;
import org.springframework.stereotype.Service;
import result.Result;

import java.util.List;

/**
* @author Lenovo
* @description 针对表【sys_menu(sys_menu)】的数据库操作Service实现
* @createDate 2023-04-08 20:25:21
*/
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu>
    implements SysMenuService{

    @Override
    public List<SysMenu> listMenu() {
        //得到一级菜单
        LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysMenu::getMenuIslink, 1)
                .eq(SysMenu::getMenuState, 0)
                .orderByAsc(SysMenu::getMenuSequ);
        List<SysMenu> topList = list(wrapper);
        for (SysMenu sysMenu : topList) {
            //查询所有二级
            wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysMenu::getSysMenuId, sysMenu.getMenuId())
                    .eq(SysMenu::getMenuState, 0)
                    .orderByAsc(SysMenu::getMenuSequ);
            List<SysMenu> secondList = list(wrapper);
            for (SysMenu menu : secondList) {
                //查询所有三级
                wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(SysMenu::getSysMenuId, menu.getMenuId())
                        .eq(SysMenu::getMenuState, 0)
                        .orderByAsc(SysMenu::getMenuSequ);
                List<SysMenu> thirdList = list(wrapper);
                menu.setChildren(thirdList);
            }
            sysMenu.setChildren(secondList);
        }
        return topList;
    }
}




